package com.firmiana.jt809.parser;

import com.firmiana.jt809.entity.MainLinkLoginEntity;

/**
 * @author hucl
 * @date 2020/8/25 17:52
 */
public class LoginEntityParser {

    public static MainLinkLoginEntity parse(String msg) {
        MessageParser messageParser = new MessageParser(msg);
        String userId = String.valueOf(messageParser.getInt(4));
        String password = messageParser.getString(8);
        String subLinkServerIp = messageParser.getString(32);
        int port = messageParser.getInt(2);
        return MainLinkLoginEntity.builder()
                .userId(userId)
                .password(password)
                .subLinkServerIp(subLinkServerIp)
                .subLinkServerPort(port)
                .build();
    }

    public static MainLinkLoginEntity mock() {
        return MainLinkLoginEntity.builder()
                .userId("123")
                .password("abc")
                .subLinkServerIp("127.0.0.1")
                .subLinkServerPort(7777)
                .build();
    }
}
